package dobest.ray.com.jiongjiong.views;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import dobest.ray.com.jiongjiong.R;

/**
 * Created by Ray on 2016/3/11.
 * https://github.com/ray0807
 */
public class CoustomNoticeDialog implements View.OnClickListener {
    private Context c;
    private Dialog dialog;
    private TextView tv_title;
    private TextView tv_context;
    private TextView tv_cancle;
    private TextView tv_confirm;
    private View v_divide;
    private boolean isSigleButton = false;


    public CoustomNoticeDialog(Context c) {
        this.c = c;
        init();
    }

    public CoustomNoticeDialog(Context c, boolean isSigleButton) {
        this.c = c;
        this.isSigleButton = isSigleButton;
        init();
    }

    private void init() {
        dialog = new Dialog(c, R.style.CustomDialog);
        LayoutInflater inflater = LayoutInflater.from(c);
        final View v1 = inflater.inflate(R.layout.layout_coustom_notice_dialog, null);
        dialog.setContentView(v1);// 设置使用View
        tv_title = (TextView) v1.findViewById(R.id.tv_title);
        tv_context = (TextView) v1.findViewById(R.id.tv_context);
        tv_cancle = (TextView) v1.findViewById(R.id.tv_cancle);
        tv_confirm = (TextView) v1.findViewById(R.id.tv_confirm);
        v_divide = v1.findViewById(R.id.v_divide);
        if (isSigleButton) {
            tv_cancle.setVisibility(View.GONE);
            v_divide.setVisibility(View.GONE);
        }
        tv_cancle.setOnClickListener(this);
    }

    public void setTitle(String title) {
        tv_title.setText(title);
    }

    public void setContent(String content) {
        tv_context.setText(content);
    }

    public void setConfirmListener(View.OnClickListener listener) {
        tv_confirm.setOnClickListener(listener);
    }

    public void show() {
        if (!dialog.isShowing())
            dialog.show();
    }

    public void dismiss() {
        if (dialog.isShowing())
            dialog.dismiss();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancle:
                dismiss();
                break;
        }
    }
}
